package com.tedu.weibo.comment.result;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 统一结果响应
 * 规范Controller向前端回复的格式
 * 格式由JSON对象表达，对应三个属性
 * int status:状态代码
 * String msg:描述信息
 * Object data:数据，向前端发送处理结果数据
 */
@Getter  //不用@data注解是为了不生成tostring方法
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer status;
    private String msg;
    private Object data;

    public JsonResult(StatusCode status) {
        this.status = status.getStatusCode();
        this.msg = status.getMessage();
    }
    public JsonResult(StatusCode status, Object data) {
       // this();  调用本类的无参构造器 JsonResult()
        this(status);//调用本类的JsonResult(StatusCode status)构造器
        this.data = data;
    }

    public static JsonResult sucess(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult sucess() {
        return sucess(null);
      //  return new JsonResult(StatusCode.OPERATION_SUCCESS)  上面那一句等同于这句
    }
}
